<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$intOID = (int)$_data["OddsID"];
$intNewUpdateTime = (int)$_data["NewUpdateTime"];
$intGambleID = (int)$_data["GambleID"];
$strBT = trim($_data["Bet_Type"]);
	
$strWagerType = "-1";
$intUserID = $_SESSION["Admin_Info"] -> ID;
$isGetWDateFromTodyGame = false;
switch($arrPower[1]){
	case "all":
		$strSeach = " ";
		$strSeach2 = " ";
		$strMulti = "*b.Layer6Rate";
		$strComm = "*b.Layer6Commission";
		$strWagerType = "0,1,2,3,4,5,6";
		$strSWType = "-999";
		$isGetWDateFromTodyGame = true;
		break;

	case "layer6-sub":
		$intUserID = $_SESSION["Admin_Info"] -> ParentID;
	case "layer6":
		if($isRealShow == 2 && $_SESSION["Admin_Info"] -> isShowAllReport == 1){	//公司總帳
			$strSeach = " ";
			$strMulti = "*b.Layer6Rate";
			$strComm = "*b.Layer6Commission";
			$strWagerType = "0,1,2,3,4,5,6";
			$strSWType = "-999";
		}else{
			$strSeach = " and b.Layer6ID = ".$intUserID." ";
			$strMulti = "*(b.DirectorRate - b.Layer6Rate)";
			$strComm = "*b.DirectorCommission";
			$strWagerType = "0,2,3,4,5,6";
			$strSWType = "6";
		}
		break;

	case "director-sub":
		$intUserID = $_SESSION["Admin_Info"] -> ParentID;
	case "director":
		if($isRealShow == 2 && $_SESSION["Admin_Info"] -> isShowAllReport == 1){	//公司總帳
			$strSeach = " and b.Layer6ID = ".$_SESSION["Admin_Info"] -> ParentID." ";
			$strMulti = "*b.DirectorRate";
			$strComm = "*b.DirectorCommission";
			$strWagerType = "0,2,3,4,5,6";
			$strSWType = "-999";
		}else{
			$strSeach = " and b.DirectorID = ".$intUserID." ";
			$strMulti = "*(b.StockRate - b.DirectorRate)";
			$strComm = "*b.StockCommission";
			$strWagerType = "0,2,3,4,5";
			$strSWType = "5";
		}
		break;

	case "stock-sub":
		$intUserID = $_SESSION["Admin_Info"] -> ParentID;
	case "stock":
		$strSeach = " and b.StockID = ".$intUserID." ";
		$strMulti = "*(b.MainRate - b.StockRate)";
		$strComm = "*b.MainCommission";
		$strWagerType = "0,2,3,4";
		$strSWType = "4";
		break;

	case "main-sub":
		$intUserID = $_SESSION["Admin_Info"] -> ParentID;
	case "main":
		$strSeach = " and b.MainID = ".$intUserID." ";
		$strMulti = "*(b.SubRate - b.MainRate)";
		$strComm = "*b.SubCommission";
		$strWagerType = "0,2,3";
		$strSWType = "3";
		break;

	case "sub-sub":
		$intUserID = $_SESSION["Admin_Info"] -> ParentID;
	case "sub";
		$strSeach = " and b.SubID = ".$intUserID." ";
		$strMulti = "*(1 - b.SubRate)";
		$strComm = "*b.MemCommission";
		$strWagerType = "0,2";
		$strSWType = "2";
		break;
}

//取出有下注累積金額異動的資料
if($isGetWDateFromTodyGame){
	$strSQL = "select * from `bet_TodayGame".$intLID."` where `GambleID` = '".$intGambleID."' and `Bet_Type` != 15 and `UpdateTime` > ".$intNewUpdateTime." order by `Bet_Type`, `Number`";
}else{
	$strSQL = "select * from `bet_RealTodayGame".$intLID."` where `GambleID` = '".$intGambleID."' and `UserID` = ".$intUserID." and `Bet_Type` != 15 and `UpdateTime` > ".$intNewUpdateTime." order by `Bet_Type`, `Number` ";
}

if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Find Wager Data Error!!";
	$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
	ErrMsgOutputHTML("LoginError", "", 1);
}

$arrUpBT = array();
while($Rows = PMA_mysql_fetch_object($RS)){
	$strCon .= "parent.arrWager[".$Rows -> Bet_Type."][".$Rows -> Number."]={BT:".$Rows -> Bet_Type.
		",Num:".$Rows -> Number.
		",tolW:".$Rows -> tolWager.
		",tolS:".round($Rows -> tolStake, 3).
		",tolP:".round($Rows -> tolPayOff, 3).
		",tolC:".round($Rows -> tolCommission, 4).
		",tolRS:".round($Rows -> tolRealStake, 3).
		",tolRP:".round($Rows -> tolRealPayOff, 3).
		",tolSS:".round($Rows -> tolSuppleStake, 3).
		",tolSP:".round($Rows -> tolSupplePayOff, 3).
		",tolSC:".round($Rows -> tolSuppleCommission, 4).
		"};\n";
	if($intNewUpdateTime < $Rows -> UpdateTime)$intNewUpdateTime = $Rows -> UpdateTime;
	$arrUpBT[$Rows -> Bet_Type] = $Rows -> Bet_Type;
}

//取出最新賠率
//不含過關
$strSQL = "select * from `bet_TodayGame".$intLID."` where `GambleID` = '".$intGambleID."' and `Bet_Type` != 15 and `OddsID` > ".$intOID." order by `Bet_Type`, `Number`";
if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Find TodayGame Data Error!!";
	$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}

while($Rows = PMA_mysql_fetch_object($RS)){
	$strCon .= "parent.arrGame[".$Rows -> Bet_Type."][".$Rows -> Number."]={GID:".$Rows -> GambleID.
		",BT:".$Rows -> Bet_Type.
		",Num:".$Rows -> Number.
		",Odds:".round($Rows -> Odds, 3).
		",isStop:".$Rows -> isStopBet.
		"};\n";

	if($intOID < $Rows -> OddsID)$intOID = $Rows -> OddsID;
	$arrUpBT[$Rows -> Bet_Type] = $Rows -> Bet_Type;
}

//過關的處理
$strSQL = "select a.Bet_Type as Bet_Type, a.Number as Number, SUM(b.MemStake) as tolStake, SUM(b.MemPayOff) as tolPayOff, SUM(b.MemStake*b.MemExchangeRate".$strMulti.") as tolRealStake, SUM(b.MemPayOff*MemExchangeRate".$strMulti.") as tolRealPayOff, COUNT(*) as tolWager, SUM(b.MemStake*b.MemExchangeRate".$strMulti.$strComm.") as tolCommission  from `bet_ParlaysNumber` a, `bet_BetListTmp` b where a.BetListID = b.ID and b.GambleID = '".$intGambleID."' and b.Bet_Type = 15 ".$strSeach." group by a.Bet_Type, a.Number";
if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Find TodayGame Data Error!!";
	$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}
$intNo = 0;
while($Rows = PMA_mysql_fetch_object($RS)){
	$strCon .= "parent.arrGame[15][".$Rows -> Bet_Type.$Rows -> Number."]={BT:".$Rows -> Bet_Type.
		",Num:".$Rows -> Number.
		",tolW:".$Rows -> tolWager.
		",tolS:".round($Rows -> tolStake, 3).
		",tolP:".round($Rows -> tolPayOff, 3).
		",tolC:".round($Rows -> tolCommission, 4).
		",tolRS:".round($Rows -> tolRealStake, 3).
		",tolRP:".round($Rows -> tolRealPayOff, 3).
		"};\n";
	$intNo++;
}
$arrUpBT[15] = 15;

/*=================================================================*/
header("Cache-Control: no-store, no-cache, must-revalidate");	  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");															  // HTTP/1.0
?><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript">
<!--
<?php 
print $strCon."\n";

print "parent.PageConfig.NewUpdateTime = ".$intNewUpdateTime.";\n";
print "parent.PageConfig.NewOddsID = ".$intOID.";\n";
print "parent.PageConfig.UpdateBetType = '".implode(",", $arrUpBT)."';\n";

print "parent.setOddsObject();\n";
?>
//-->
</script>